//
//  LSPromptAlertVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/8/12.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "LSPromptAlertVC.h"
#import "LSPromptAlertView.h"

@interface LSPromptAlertVC ()
@end

@implementation LSPromptAlertVC

- (LSPromptAlertView *)PromptAlertView
{
    if (!_PromptAlertView) {
        self.PromptAlertView = [[[NSBundle mainBundle] loadNibNamed:@"LSPromptAlertView" owner:self options:nil] lastObject];
    }
    return _PromptAlertView;
}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:YES];
    [self sendRequest];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.PromptAlertView.frame = CGRectMake((screenW - 280)/2, (screenH - 280)/2, 280, 280);
    
    self.PromptAlertView.backgroundColor = [UIColor whiteColor];
    self.PromptAlertView.layer.cornerRadius = 10.f;
    self.PromptAlertView.layer.masksToBounds = YES;
    
    self.PromptAlertView.topView.layer.masksToBounds = YES;
    self.PromptAlertView.topView.layer.cornerRadius = 5.0f;
    self.PromptAlertView.topView.layer.borderWidth = 0.5f;
    self.PromptAlertView.topView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    self.PromptAlertView.bottomView.layer.masksToBounds = YES;
    self.PromptAlertView.bottomView.layer.cornerRadius = 5.0f;
    self.PromptAlertView.bottomView.layer.borderWidth = 0.5f;
    self.PromptAlertView.bottomView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    self.PromptAlertView.alipayBtn.layer.masksToBounds =YES;
    self.PromptAlertView.alipayBtn.layer.cornerRadius = 5.0f;
    self.PromptAlertView.alipayBtn.layer.borderWidth = 0.5f;
    self.PromptAlertView.alipayBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    [self.view addSubview:self.PromptAlertView];
    
    self.view.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.5];
    
    // 按钮监听
    [self.PromptAlertView.cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];

}

-(void)cancel{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 请求数据
-(void)sendRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    dic[@"token"] = allConstMemberToken;
    dic[@"userId"] = allConstMemberid;

    
    [LSHttpTool sendHttpData:@"getUserBalance_app_pay.im.lensum" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        NSString * balanceStr = [YZBase64 textFromBase64String:dicInfo[@"data"][@"balance"]];
        self.PromptAlertView.balanceLabel.text = [NSString stringWithFormat:@"￥%@",balanceStr];
        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:@"网络连接错误"];
    }];
    
}
@end
